<template>
	<!-- 巡检任务清单的弹窗 -->
  <p-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <p-spin :spinning="confirmLoading">
      <p-form :form="form">
        <p-row>
		  <p-col  :span="8">
			<p-form-item label="送检单号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'inspectBillno', validatorRules.inspectBillno]" placeholder="请输入送检单号"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="产品编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<f-popup
						contextPath="mes-quality"
						v-decorator="['mcode', validatorRules.mcode]"
						:trigger-change="true"
						org-fields="mid,mcode,mname,sprc"
						dest-fields="mid,mcode,mname,sprc"
						code="mes_cctv_plan_mcode"
						@callback="popupCallback"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="产品名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'mname', validatorRules.mname]" placeholder="请输入产品名称"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="一级工序" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'processOne', validatorRules.processOne]" placeholder="请输入一级工序"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="二级工序" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'processTwo', validatorRules.processTwo]" placeholder="请输入二级工序"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="线体" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'linename', validatorRules.linename]" placeholder="请输入线体"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="工序工单" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'processBillno', validatorRules.processBillno]" placeholder="请输入工序工单"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="工艺更改单单号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'processChangesBillno', validatorRules.processChangesBillno]" placeholder="请输入工艺更改单单号"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="操作时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-date    placeholder="请选择操作时间" v-decorator="[ 'operationDt', validatorRules.operationDt]" :trigger-change="true" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="检验结果" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-dict-select-tag  type="radio" v-decorator="['inspectResult', validatorRules.inspectResult]" :trigger-change="true" dictCode="mes_is_qualified" placeholder="请选择检验结果"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="送检时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-date    placeholder="请选择送检时间" v-decorator="[ 'sendTime', validatorRules.sendTime]" :trigger-change="true" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="触发方式" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'triggerMethod', validatorRules.triggerMethod]" placeholder="请输入触发方式"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="检验频次" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'inspectFrequency', validatorRules.inspectFrequency]" placeholder="请输入检验频次" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="抽样方式" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-dict-select-tag  type="list" v-decorator="['simpleMethod', validatorRules.simpleMethod]" :trigger-change="true" dictCode="rc_inspect_method" placeholder="请选择抽样方式"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="抽样数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'simpleQty', validatorRules.simpleQty]" placeholder="请输入抽样数量"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="任务触发时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-date    placeholder="请选择任务触发时间" v-decorator="[ 'taskTraggerTime', validatorRules.taskTraggerTime]" :trigger-change="true" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="复核结果" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-dict-select-tag  type="list" v-decorator="['reviewResult', validatorRules.reviewResult]" :trigger-change="true" dictCode="mes_review_result" placeholder="请选择复核结果"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="整改情况" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'changeCondition', validatorRules.changeCondition]" placeholder="请输入整改情况"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="送检维度" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'sendDimension', validatorRules.sendDimension]" placeholder="请输入送检维度"></p-input>
			</p-form-item>
		  </p-col>
        </p-row>


      </p-form>
    </p-spin>
  </p-modal>
</template>

<script>


  import { SubmitOnchangMixin } from '@/mixins/SubmitOnchangMixin'
  import { httpAction, putAction, api } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"

  export default {
    name: "MesQcTourInspectTaskModal",
	mixins: [SubmitOnchangMixin],
    components: { 
      JDate,
      JDictSelectTag,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title: '操作',
        width: 1200,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 8 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        inspectBillno:{rules: [{ required: false, message: '请输入送检单号!' }]},
        mcode:{rules: [{ required: false, message: '请输入产品编码!' }]},
        mname:{rules: [{ required: false, message: '请输入产品名称!' }]},
        processOne:{rules: [{ required: false, message: '请输入一级工序!' }]},
        processTwo:{rules: [{ required: false, message: '请输入二级工序!' }]},
        linename:{rules: [{ required: false, message: '请输入线体!' }]},
        processBillno:{rules: [{ required: false, message: '请输入工序工单!' }]},
        processChangesBillno:{},
        operationDt:{rules: [{ required: false, message: '请输入操作时间!' }]},
        inspectResult:{rules: [{ required: false, message: '请输入检验结果!' }]},
        sendTime:{},
        triggerMethod:{},
        inspectFrequency:{rules: [{ required: false, message: '请输入检验频次!' }]},
        simpleMethod:{rules: [{ required: false, message: '请输入抽样方式!' }]},
        simpleQty:{rules: [{ required: false, message: '请输入抽样数量!' }]},
        taskTraggerTime:{},
        reviewResult:{rules: [{ required: false, message: '请输入复核结果!' }]},
        changeCondition:{rules: [{ required: false, message: '请输入整改情况!' }]},
        sendDimension:{rules: [{ required: false, message: '请输入送检维度!' }]},
        },
        url: {
          add: '/mes-quality/mesQcTourInspectTask/add',
          edit: '/mes-quality/mesQcTourInspectTask/edit',
        }
     
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
        this.getRuleCodeValue();
      },
      getRuleCodeValue() {
        let param = {
          commonFormData: this.model,
          rules: [
            {"ruleCode": "mes_tour_inspect_billno_rule", "columnName": "inspectBillno"},
            ]
        }

        putAction(api.ruleBaseURL, param).then(res => {
          // 执行成功，获取返回的值，并赋到页面上
          if (res.success) {
            console.log("生成的编码：" + res.data)
            const item = res.data;
            this.form.setFieldsValue(pick(item, Object.keys(item)))
          }
        })
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'inspectBillno','mcode','mname','processOne','processTwo','linename','processBillno','processChangesBillno','operationDt','inspectTimes','inspectStatus','inspectResult','sendTime','triggerMethod','inspectFrequency','simpleMethod','simpleQty','taskTraggerTime','reviewResult','changeCondition','sendDimension'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
		handleOk () {
			const that = this;
			// 触发表单验证
			this.form.validateFields((err, values) => {
			  if (!err) {
				  that.confirmLoading = true;
				  let httpurl = '';
				  let method = '';
				  let formData = Object.assign(this.model, values);
				  this.formData = Object.assign(this.model, values);
				  //新增触发
				  if(!this.model.id){
					httpurl+=this.url.add;
					method = 'post';
					if(this.EnhanceJS.afterAdd){
					  //新增之前
					  let Obj = eval(this.EnhanceJS.afterAdd)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }else{
					//编辑触发
					httpurl+=this.url.edit;
					method = 'put';
					if(this.EnhanceJS.afterEdit){
					 //编辑之前
					  let Obj = eval(this.EnhanceJS.afterEdit)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }
			  }

			})
		},
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'inspectBillno','mcode','mname','processOne','processTwo','linename','processBillno','processChangesBillno','operationDt','inspectTimes','inspectStatus','inspectResult','sendTime','triggerMethod','inspectFrequency','simpleMethod','simpleQty','taskTraggerTime','reviewResult','changeCondition','sendDimension'))
      },

      
    }
  }
</script>
